<?php
// View for admin - articles
require_once WACT_ROOT.'controller/controller.inc.php';
require_once WACT_ROOT .'controller/form.inc.php';
require_once WACT_ROOT.'view/view.inc.php';
require_once WACT_ROOT .'view/formview.inc.php';

require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';

require_once 'model/common/user.php';
require_once 'model/common/article.php';
require_once 'model/common/categories.php';
require_once 'model/common/date.php';


class CategoriesListView extends LayoutFormView {

    function CategoriesListView($TemplateFile) {
        parent :: LayoutFormView($TemplateFile);
    }

    //function supressFormErrors() {
         //$dataset = array (array ());
         //$empty_set =& new ArrayDataSet($list_updated);

    	//$this->Template->setChildDataSource('Summary', $empty_set);
    //}

    function prepare(&$controller, &$request, &$responseModel) {
    	parent::prepare($controller, $request, $responseModel);
		        
		$this->Template->set('SITE_CSS',Site::getSiteTemplateCSS());
		$this->Template->set('SITE_BASE',Site::getSiteTemplateBase());
		$this->Template->set('SITE_TITLE',Site::getTitle());
 

        //populate the List
        $list =& CategoriesModel::getAllCategories();

        $list_updated=array();
        $list->reset();
        while ($list->next()) {

        	$dataspace = $list->export();
            $category_id = $list->get('category_id');
            $free = $list->get('normal');
            $premium = $list->get('premium');
            $type =  $list->get('type');

            $type_show = CategoriesModel::getHRType($type);
            $dataspace['type_show'] =  $type_show;

            if ($free) $dataspace['free_show'] =  'Yes';
            else $dataspace['free_show'] =  'No';
            if ($premium) $dataspace['premium_show'] =  'Yes';
            else $dataspace['premium_show'] =  'No';

            // populate linked categories field
            $linked_categories = CategoriesModel::getLinkedCategories($category_id);
            $dataspace['linked_categories'] =  $linked_categories;


            $list_updated[$category_id] = $dataspace;
        }


        $list_source_updated =& new ArrayDataSet($list_updated);
        $this->Template->setChildDataSource('List', $list_source_updated);

    	//populate type combo
        $type =& $this->Template->getChild('type');
        $types = array('1'=>'Sport category','2'=>'Sports Community','3'=>'Other');
        $type->setChoices($types);

        //populate categories
        $categories1 =& CategoriesModel::getSportCategories(false,false);
        $categories2 =& CategoriesModel::getCommunityCategories(false,false);
        $category1 =& $this->Template->getChild('linked1');
        $category2 =& $this->Template->getChild('linked2');
        $category1->setChoices($categories1);
        $category2->setChoices($categories2);

        //populate linked categories
        $category_id = $responseModel->get('category_id');
        if ( $category_id ) {
        	$linked =& CategoriesModel::loadLinkedcategories($category_id);
        	$category1->setSelection($linked);
            $category2->setSelection($linked);
        }

    	return;


    }

}






?>